<template>
  <div class="teacher-detail-container">
    <div class="teacher-header">
      <div class="avatar-section">
        <img :src="teacher.avatar" :alt="teacher.teacherName" class="avatar">
        <div class="status-badge" :class="{ 'approved': teacher.status === 'approved' }">
          {{ teacher.status === 'approved' ? '已认证' : '未认证' }}
        </div>
      </div>
      <div class="header-content">
        <div class="info-section">
          <h1 class="teacher-name">{{ teacher.teacherName }}
            <span class="gender-tag">{{ teacher.gender === '男' ? '♂' : '♀' }}</span>
          </h1>
          <div class="basic-tags">
            <span class="tag">{{ teacher.age }}岁</span>
            <span class="tag">{{ teacher.education }}</span>
            <span class="tag">{{ teacher.school }}</span>
            <span class="tag">{{ teacher.major }}</span>
          </div>
          <div class="certification">
            <i class="el-icon-medal"></i>
            {{ teacher.certification }}
          </div>
        </div>
        <div class="contact-section">
          <div class="price">
            <span class="amount">¥{{ teacher.hourlyRate }}</span>/小时
          </div>
          <div class="action-buttons">
            <el-button type="primary" @click="showContact">联系教员</el-button>
            <el-button type="success" @click="showAppointmentDialog">预约教员</el-button>
          </div>
        </div>
      </div>
    </div>

    <div class="teacher-content">
      <div class="content-section">
        <h2 class="section-title">
          <i class="el-icon-user"></i>
          教学经验
        </h2>
        <div class="section-content">{{ teacher.teachingExp || '暂无教学经验' }}</div>
      </div>

      <div class="content-section">
        <h2 class="section-title">
          <i class="el-icon-notebook-1"></i>
          个人简介
        </h2>
        <div class="section-content">{{ teacher.introduction || '暂无个人简介' }}</div>
      </div>

      <div class="content-section">
        <h2 class="section-title">
          <i class="el-icon-reading"></i>
          教学科目
        </h2>
        <div class="section-content">
          <el-tag type="success">{{ teacher.teachingcategoryName }}</el-tag>
        </div>
      </div>

      <div class="content-section">
        <h2 class="section-title">
          <i class="el-icon-phone"></i>
          联系方式
        </h2>
        <div class="section-content contact-info">
          <p><i class="el-icon-mobile-phone"></i> 手机：{{ isContactVisible ? teacher.phoneNumber : '***********' }}</p>
          <p><i class="el-icon-message"></i> 邮箱：{{ isContactVisible ? teacher.email : '***********' }}</p>
        </div>
      </div>
    </div>

    <!-- 添加预约对话框 -->
    <el-dialog
      title="预约教员"
      :visible.sync="appointmentDialogVisible"
      width="600px">
      <el-form :model="appointmentForm" :rules="rules" ref="appointmentForm" label-width="100px">
        <el-form-item label="预约时间" prop="timeRange">
          <el-date-picker
            v-model="appointmentForm.timeRange"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            :default-time="['09:00:00', '18:00:00']">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="预约说明" prop="detail">
          <el-input
            type="textarea"
            :rows="4"
            placeholder="请输入预约说明，如具体辅导需求、时间安排等"
            v-model="appointmentForm.detail">
          </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="appointmentDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitAppointment">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getTeacherDetailByTeacherId } from "@/api/profile/profile";
import { addAppointment } from "@/api/appointment/appointment";
export default {
  name: 'TeacherDetail',
  data() {
    return {
      teacherId: '',
      teacher: {},
      isContactVisible: false,
      appointmentDialogVisible: false,
      appointmentForm: {
        parentName: '',
        phoneNumber: '',
        timeRange: [],
        detail: '',
        teacherName: ''
      },
      rules: {
        parentName: [
          { required: true, message: '请输入家长姓名', trigger: 'blur' },
          { min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' }
        ],
        phoneNumber: [
          { required: true, message: '请输入联系电话', trigger: 'blur' },
          { pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号码', trigger: 'blur' }
        ],
        timeRange: [
          { type: 'array', required: true, message: '请选择预约时间范围', trigger: 'change' }
        ],
      }
    }
  },
  created() {
    this.teacherId = this.$route.query.id
    this.getTeacherDetailByTeacherId()
  },
  methods: {
    getTeacherDetailByTeacherId() {
      getTeacherDetailByTeacherId(this.teacherId).then(response => {
        this.teacher = response
        console.log(this.teacher)
      })
    },
    showContact() {
      this.isContactVisible = true
    },
    showAppointmentDialog() {
      this.appointmentForm.teacherName = this.teacher.teacherName;
      this.appointmentDialogVisible = true;
    },
    submitAppointment() {
      this.$refs.appointmentForm.validate((valid) => {
        if (valid) {
          const appointmentData = {
            parentName: localStorage.getItem("userName"),
            phoneNumber: localStorage.getItem("parentPhoneNumber"),
            teacherName: this.teacher.teacherName,
            detail: this.appointmentForm.detail,
            startTime: this.appointmentForm.timeRange[0],
            endTime: this.appointmentForm.timeRange[1],
            appointmentStatus: "pending"
          };
          addAppointment(appointmentData).then(response => {
            this.$message.success('预约提交成功，请等待教员确认');
            this.appointmentDialogVisible = false;
            this.$refs.appointmentForm.resetFields();
          }).catch(error => {
            this.$message.error('预约提交失败：' + error.message);
          });
        }
      });
    }
  }
}
</script>

<style lang="scss" scoped>
@keyframes fadeInUp {
  0% {
    opacity: 0;
    transform: translateY(40px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes badgePop {
  0% {
    transform: translateX(-50%) scale(0.6);
    opacity: 0;
  }
  60% {
    transform: translateX(-50%) scale(1.15);
    opacity: 1;
  }
  100% {
    transform: translateX(-50%) scale(1);
    opacity: 1;
  }
}

.teacher-detail-container {
  max-width: 980px;
  min-height: 100vh;
  margin: 0 auto;
  padding: 0 12px;
  display: flex;
  flex-direction: column;
  background: linear-gradient(120deg, #f6f8fc 0%, #f1f4f9 100%);
}

.teacher-header {
  background: rgba(255, 255, 255, 0.98);
  border-radius: 18px;
  padding: 32px 40px 24px 40px;
  box-shadow: 0 8px 32px rgba(64, 158, 255, 0.08), 0 1.5px 8px rgba(230,30,30,0.04);
  border: 1px solid #f0f2f5;
  margin-top: 28px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 32px;
  animation: fadeInUp 0.7s cubic-bezier(0.23, 1, 0.32, 1);
}

.avatar-section {
  flex: 0 0 120px;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  .avatar {
    width: 110px;
    height: 110px;
    border-radius: 50%;
    object-fit: cover;
    border: 4px solid #fff;
    box-shadow: 0 4px 24px rgba(64, 158, 255, 0.10);
    transition: transform 0.35s cubic-bezier(0.23, 1, 0.32, 1), box-shadow 0.35s cubic-bezier(0.23, 1, 0.32, 1);
    background: #f6f8fc;
  }
  .avatar:hover {
    transform: scale(1.09);
    box-shadow: 0 8px 32px rgba(64, 158, 255, 0.18);
  }
  .status-badge {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(90deg, #67C23A 60%, #a8ebaf 100%);
    color: #fff;
    padding: 4px 18px;
    border-radius: 16px;
    font-size: 15px;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(103, 194, 58, 0.12);
    letter-spacing: 1px;
    margin-top: 8px;
    white-space: nowrap;
    line-height: 1;
    text-align: center;
    animation: badgePop 0.7s cubic-bezier(0.23, 1, 0.32, 1);
  }
}

.header-content {
  flex: 1 1 0;
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  justify-content: space-between;
  min-width: 0;
}

.info-section {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0 32px 0 0;
  .teacher-name {
    font-size: 28px;
    margin: 0 0 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: #222;
    font-weight: 700;
    .gender-tag {
      font-size: 18px;
      color: #409EFF;
      background: rgba(64, 158, 255, 0.12);
      padding: 2px 10px;
      border-radius: 14px;
      font-weight: 500;
    }
  }
  .basic-tags {
    margin-bottom: 14px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    .tag {
      background: #f4f4f5;
      color: #606266;
      padding: 5px 14px;
      border-radius: 14px;
      font-size: 13px;
      border: 1px solid #e6e8eb;
      font-weight: 500;
    }
  }
  .certification {
    color: #E6A23C;
    font-size: 14px;
    display: flex;
    align-items: center;
    background: rgba(230, 162, 60, 0.10);
    padding: 7px 16px;
    border-radius: 10px;
    width: fit-content;
    font-weight: 500;
    i {
      margin-right: 7px;
      font-size: 17px;
    }
  }
}

.contact-section {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: flex-start;
  min-width: 180px;
  .price {
    margin-bottom: 18px;
    color: #fff;
    font-size: 18px;
    background: linear-gradient(90deg, #e61e1e 60%, #ffb199 100%);
    padding: 8px 18px;
    border-radius: 18px;
    display: inline-block;
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(230, 30, 30, 0.10);
    .amount {
      font-size: 26px;
      font-weight: bold;
    }
  }
  .action-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    .el-button {
      padding: 10px 22px;
      font-size: 15px;
      border-radius: 10px;
      font-weight: 600;
      box-shadow: 0 2px 8px rgba(64, 158, 255, 0.08);
      transition: transform 0.22s cubic-bezier(0.23, 1, 0.32, 1), box-shadow 0.22s cubic-bezier(0.23, 1, 0.32, 1);
    }
    .el-button--primary {
      background: linear-gradient(90deg, #409EFF 60%, #6ec6ff 100%);
      border: none;
      color: #fff;
    }
    .el-button--success {
      background: linear-gradient(90deg, #67C23A 60%, #a8ebaf 100%);
      border: none;
      color: #fff;
    }
  }
  .el-button:hover {
    transform: translateY(-3px) scale(1.04);
    box-shadow: 0 6px 18px rgba(64, 158, 255, 0.18);
  }
}

.teacher-content {
  flex: 1 1 auto;
  margin-top: 18px;
  background: rgba(255, 255, 255, 0.98);
  border-radius: 18px;
  padding: 38px 44px 38px 44px;
  box-shadow: 0 8px 32px rgba(64, 158, 255, 0.08), 0 1.5px 8px rgba(230,30,30,0.04);
  border: 1px solid #f0f2f5;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  min-height: 0;
  animation: fadeInUp 0.9s 0.2s cubic-bezier(0.23, 1, 0.32, 1) backwards;
}
.teacher-content .content-section {
  margin-bottom: 28px;
  padding: 0 0 0 0;
  background: transparent;
  border-radius: 12px;
  border-bottom: 1px solid #f0f2f5;
  transition: background 0.2s;
}
.teacher-content .content-section:last-child {
  margin-bottom: 0;
  border-bottom: none;
}
.teacher-content .section-title {
  font-size: 18px;
  color: #222;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  i {
    color: #e61e1e;
    font-size: 22px;
  }
}
.teacher-content .section-content {
  color: #606266;
  line-height: 2.0;
  font-size: 15px;
  padding: 0 0 8px 0;
  background: none;
  border-radius: 0;
}
.teacher-content .contact-info p {
  margin: 8px 0;
  display: flex;
  align-items: center;
  i {
    margin-right: 8px;
    color: #409EFF;
    font-size: 17px;
  }
}

.el-dialog {
  border-radius: 16px;
  .el-dialog__header {
    background: #f8f9fa;
    padding: 18px 28px;
    border-bottom: 1px solid #eee;
  }
  .el-dialog__body {
    padding: 28px;
  }
  .el-dialog__footer {
    padding: 18px 28px;
    border-top: 1px solid #eee;
  }
  .el-date-picker {
    width: 100%;
  }
  .el-form-item {
    margin-bottom: 18px;
  }
  .el-input__inner,
  .el-textarea__inner {
    border-radius: 8px;
    border: 1px solid #dcdfe6;
    font-size: 15px;
    padding: 8px 12px;
    transition: border 0.2s;
  }
  .el-input__inner:focus,
  .el-textarea__inner:focus {
    border-color: #409EFF;
    box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.08);
  }
}
</style> 